package com.zzyl;

import okhttp3.*;
import org.json.JSONObject;
import java.util.concurrent.TimeUnit;

import java.io.*;


/**
 * 需要添加依赖
 * <!-- https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp -->
 * <dependency>
 *     <groupId>com.squareup.okhttp3</groupId>
 *     <artifactId>okhttp</artifactId>
 *     <version>4.12.0</version>
 * </dependency>
 */

class Sample {

    public static final OkHttpClient HTTP_CLIENT = new OkHttpClient().newBuilder().readTimeout(300, TimeUnit.SECONDS).build();

    public static void main(String []args) throws IOException{
        MediaType mediaType = MediaType.parse("application/json");
        RequestBody body = RequestBody.create(mediaType, "{\"model\":\"ernie-4.5-turbo-128k\",\"messages\":[{\"role\":\"user\",\"content\":\"您好\"}],\"web_search\":{\"enable\":false,\"enable_citation\":false,\"enable_trace\":false},\"plugin_options\":{}}");
        Request request = new Request.Builder()
            .url("https://qianfan.baidubce.com/v2/chat/completions")
            .method("POST", body)
            .addHeader("Content-Type", "application/json")
            .addHeader("appid", "")
            .addHeader("Authorization", "Bearer bce-v3/ALTAK-XMJyiiafaac5aRfjklHHC/80002434a65436d2fd0f79df97a1104e8f0262ef")
            .build();
        Response response = HTTP_CLIENT.newCall(request).execute();
        System.out.println(response.body().string());

    }
    
    
}